package other;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * Creared with IntelliJ IDEA.
 * Description:三元组

 * Time:19:39
 */
public class Mei4 {


    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        int n =  Integer.parseInt(cin.nextLine());
        int[] nums = Arrays.stream(cin.nextLine().split(" ")).mapToInt(Integer::valueOf).toArray();
        long count = 0;
        Map<Integer, Integer> mp = new HashMap<>();
        mp.put(nums[n - 1], 1);
        for (int i = n - 2; i >= 1; i--) {
            for (int j = i - 1; j >= 0; j--) {
                count += mp.getOrDefault(3 * nums[i] - nums[j], 0);
            }
            mp.put(nums[i], mp.getOrDefault(nums[i], 0) + 1);
        }
        System.out.println(count);
    }
}
